﻿#pragma once
#include <string>
#include <unordered_map>
#include <vector>
#include <iomanip>
#include <sstream>
class LunarUtil
{
public:
	/// <summary>
	/// 月份地支偏移量，因正月起寅
	/// </summary>
	static const int BASE_MONTH_ZHI_INDEX = 2;
	/// <summary>
	/// 旬
	/// </summary>
	static const std::vector<std::string> XUN;

	/// <summary>
	   /// 旬空
	   /// </summary>
	static const std::vector<std::string> XUN_KONG;

	/// <summary>
	/// 六曜
	/// </summary>
	static const std::vector<std::string> LIU_YAO;

	/// <summary>
	/// 候
	/// </summary>
	static const std::vector<std::string> HOU;

	/// <summary>
	/// 物候
	/// </summary>
	static const std::vector<std::string> WU_HOU;


	/// <summary>
		/// 天干
		/// </summary>
	static const std::vector<std::string>  GAN;

	/// <summary>
	/// 喜神方位，《喜神方位歌》：甲己在艮乙庚乾，丙辛坤位喜神安。丁壬只在离宫坐，戊癸原在在巽间。
	/// </summary>
	static const std::vector<std::string> POSITION_XI;

	/// <summary>
	/// 阳贵方位，《阳贵神歌》：甲戊坤艮位，乙己是坤坎，庚辛居离艮，丙丁兑与乾，震巽属何日，壬癸贵神安。
	/// </summary>
	static const std::vector<std::string> POSITION_YANG_GUI;

	/// <summary>
	/// 阴贵方位，《阴贵神歌》：甲戊见牛羊，乙己鼠猴乡，丙丁猪鸡位，壬癸蛇兔藏，庚辛逢虎马，此是贵神方。
	/// </summary>
	static const std::vector<std::string> POSITION_YIN_GUI;

	/// <summary>
	/// 《福神方位歌》流派1：甲乙东南是福神，丙丁正东是堪宜，戊北己南庚辛坤，壬在乾方癸在西。
	/// </summary>
	static const std::vector<std::string> POSITION_FU;

	/// <summary>
	///《福神方位歌》流派2：甲己正北是福神，丙辛西北乾宫存，乙庚坤位戊癸艮，丁壬巽上好追寻。
	/// </summary>
	static const std::vector<std::string> POSITION_FU_2;

	/// <summary>
	/// 财神方位，《财神方位歌》：甲乙东北是财神，丙丁向在西南寻，戊己正北坐方位，庚辛正东去安身，壬癸原来正南坐，便是财神方位真。
	/// </summary>
	static const std::vector<std::string> POSITION_CAI;

	/// <summary>
	/// 逐日胎神方位
	/// </summary>
	static const std::vector<std::string> POSITION_TAI_DAY;

	/// <summary>
	/// 逐月胎神方位
	/// </summary>
	static const std::vector<std::string> POSITION_TAI_MONTH;

	/// <summary>
	/// 年太岁方位
	/// </summary>
	static const std::vector<std::string> POSITION_TAI_SUI_YEAR;

	/// <summary>
	/// 天干方位
	/// </summary>
	static const std::vector<std::string> POSITION_GAN;

	/// <summary>
	/// 地支方位
	/// </summary>
	static const std::vector<std::string> POSITION_ZHI;

	/// <summary>
	/// 地支
	/// </summary>
	static const std::vector< std::string> ZHI;

	/// <summary>
	/// 六十甲子
	/// </summary>
	static const std::vector<std::string> JIA_ZI;
	/// <summary>
	/// 十二值星
	/// </summary>
	static const std::vector<std::string> ZHI_XING;

	/// <summary>
	/// 十二天神
	/// </summary>
	static const std::vector<std::string> TIAN_SHEN;


	/// <summary>
/// 彭祖百忌.天干
/// </summary>
	static const std::vector<std::string> PENGZU_GAN;


	/// <summary>
	   /// 彭祖百忌.地支
	   /// </summary>
	static const std::vector<std::string> PENGZU_ZHI;
	/// <summary>
	/// 数字
	/// </summary>
	static const std::vector<std::string> NUMBER;

	/// <summary>
	/// 月
	/// </summary>
	static const std::vector<std::string> MONTH;

	/// <summary>
	/// 季节
	/// </summary>
	static const std::vector<std::string> SEASON;

	/// <summary>
	/// 生效
	/// </summary>
	static const std::vector<std::string> SHENGXIAO;

	/// <summary>
	/// 日
	/// </summary>
	static const std::vector<std::string> DAY;
	/// <summary>
	/// 月相
	/// </summary>
	static const std::vector<std::string> YUE_XIANG;
	/// <summary>
	/// 地支相冲（子午相冲，丑未相冲，寅申相冲，辰戌相冲，卯酉相冲，巳亥相冲），由于地支对应十二生肖，也就对应了生肖相冲
	/// </summary>
	static const std::vector<std::string> CHONG;
	/// <summary>
	/// 天干相冲之无情之克（阳克阳，阴克阴）
	/// </summary>
	static const std::vector<std::string> CHONG_GAN;
	/// <summary>
	/// 天干相冲之有情之克（阳克阴，阴克阳）
	/// </summary>
	static const std::vector<std::string> CHONG_GAN_TIE;
	/// <summary>
	/// 天干四冲
	/// </summary>
	static const std::vector<std::string> CHONG_GAN_4;
	/// <summary>
	/// 天干五合
	/// </summary>
	static const std::vector<std::string> HE_GAN_5;
	/// <summary>
	/// 地支六合
	/// </summary>
	static const std::vector<std::string> HE_ZHI_6;


	/// <summary>
		/// 月份地支对应天神偏移下标
		/// </summary>
	static const std::unordered_map<std::string, int> ZHI_TIAN_SHEN_OFFSET;

	/// <summary>
	/// 天神类型：黄道，黑道
	/// </summary>
	static const std::unordered_map<std::string, std::string> TIAN_SHEN_TYPE;

	/// <summary>
	/// 禄（甲禄在寅，乙禄在卯，丙戊禄在巳、丁己禄在午、庚禄在申、辛禄在酉、壬禄在亥、癸禄在子）
	/// </summary>
	static const std::unordered_map<std::string, std::string> LU;

	/// <summary>
	/// 天神类型吉凶
	/// </summary>
	static const std::unordered_map<std::string, std::string> TIAN_SHEN_TYPE_LUCK;

	/// <summary>
	/// 节日
	/// </summary>
	static const std::unordered_map<std::string, std::string> FESTIVAL;

	/// <summary>
	/// 非正式节日
	/// </summary>
	static const std::unordered_map<std::string, std::vector<std::string>> OTHER_FESTIVAL;


	/// <summary>
	   /// 28星宿对照表，地支+星期
	   /// </summary>
	static const std::unordered_map<std::string, std::string> XIU;

	/// <summary>
	/// 星宿对应吉凶
	/// </summary>
	static const std::unordered_map<std::string, std::string> XIU_LUCK;


	/// <summary>
		/// 星宿歌
		/// </summary>
	static const std::unordered_map<std::string, std::string> XIU_SONG;

	/// <summary>
/// 兽
/// </summary>
	static const std::unordered_map<std::string, std::string> SHOU;


	/// <summary>
	   /// 煞
	   /// </summary>
	static const std::unordered_map<std::string, std::string> SHA;


	/// <summary>
	/// 方位描述
	/// </summary>
	static const std::unordered_map<std::string, std::string> POSITION_DESC;

	/// <summary>
	/// 宫
	/// </summary>
	static const std::unordered_map<std::string, std::string> GONG;

	/// <summary>
	/// 政
	/// </summary>
	static const std::unordered_map<std::string, std::string> ZHENG;

	/// <summary>
	/// 动物
	/// </summary>
	static const std::unordered_map<std::string, std::string> ANIMAL;

	/// <summary>
	/// 天干五行
	/// </summary>
	static const std::unordered_map<std::string, std::string> WU_XING_GAN;

	/// <summary>
	/// 地支五行
	/// </summary>
	static const std::unordered_map<std::string, std::string> WU_XING_ZHI;

	/// <summary>
	/// 纳音
	/// </summary>
	static const std::unordered_map<std::string, std::string> NAYIN;

	/// <summary>
	/// 十神，天干+天干为键
	/// </summary>
	static const std::unordered_map<std::string, std::string> SHI_SHEN;


	/// <summary>
	/// 地支藏干表，分别为主气、余气、杂气
	/// </summary>
	static const std::unordered_map <std::string, std::vector<std::string>> ZHI_HIDE_GAN;

	/// <summary>
	/// 获取HH:mm时刻的地支序号，非法的时刻返回0
	/// </summary>
	/// <param name="hm">HH:mm时刻</param>
	/// <returns>地支序号，0到11</returns>
	static int GetTimeZhiIndex(std::string& hm);

	/// <summary>
	/// 将HH:mm时刻转换为时辰（地支），非法的时刻返回子
	/// </summary>
	/// <param name="hm">HH:mm时刻</param>
	/// <returns>时辰(地支)，如子</returns>
	static std::string ConvertTime(std::string& hm);

	/// <summary>
	/// 获取干支对应的甲子序号
	/// </summary>
	/// <param name="ganZhi">干支</param>
	/// <returns>甲子序号</returns>
	static int GetJiaZiIndex(const std::string& ganZhi);

	/// <summary>
	/// 获取日宜
	/// </summary>
	/// <param name="monthGanZhi">月干支</param>
	/// <param name="dayGanZhi">日干支</param>
	/// <returns>宜</returns>
	static std::vector<std::string> GetDayYi(const std::string& monthGanZhi, const std::string& dayGanZhi);

	/// <summary>
	/// 获取日忌
	/// </summary>
	/// <param name="monthGanZhi">月干支</param>
	/// <param name="dayGanZhi">日干支</param>
	/// <returns>忌</returns>
	static std::vector<std::string> GetDayJi(const std::string& monthGanZhi, const std::string& dayGanZhi);

	/// <summary>
	/// 获取日吉神
	/// </summary>
	/// <param name="lunarMonth">月</param>
	/// <param name="dayGanZhi">日干支</param>
	/// <returns>日吉神</returns>
	static std::vector<std::string> GetDayJiShen(int lunarMonth, const std::string& dayGanZhi);

	/// <summary>
	/// 获取日凶煞
	/// </summary>
	/// <param name="lunarMonth">月</param>
	/// <param name="dayGanZhi">日干支</param>
	/// <returns>日凶煞</returns>
	static std::vector<std::string> GetDayXiongSha(int lunarMonth, const std::string& dayGanZhi);

	/// <summary>
	/// 获取时辰宜
	/// </summary>
	/// <param name="dayGanZhi">日干支</param>
	/// <param name="timeGanZhi">时干支</param>
	/// <returns>宜</returns>
	static std::vector<std::string> GetTimeYi(std::string& dayGanZhi, std::string& timeGanZhi);

	/// <summary>
	/// 获取时辰忌
	/// </summary>
	/// <param name="dayGanZhi">日干支</param>
	/// <param name="timeGanZhi">时干支</param>
	/// <returns>忌</returns>
	static  std::vector<std::string> GetTimeJi(std::string& dayGanZhi, std::string& timeGanZhi);

	/// <summary>
	/// 获取名称对应的下标
	/// </summary>
	/// <param name="name">名称</param>
	/// <param name="names">名称列表</param>
	/// <param name="offset">偏移值</param>
	/// <returns>下标</returns>
	static int find(std::string& name, const std::vector< std::string> names, int offset);

	/// <summary>
	/// 获取干支所在旬下标，0-5
	/// </summary>
	/// <param name="ganZhi">干支</param>
	/// <returns>旬下标，0-5</returns>
	static int GetXunIndex(std::string& ganZhi);

	/// <summary>
	/// 获取干支所在旬
	/// </summary>
	/// <param name="ganZhi">干支</param>
	/// <returns>旬</returns>
	static std::string GetXun(std::string& ganZhi);

	/// <summary>
	/// 获取干支所在旬对应的旬空(空亡)
	/// </summary>
	/// <param name="ganZhi">干支</param>
	/// <returns>旬空(空亡)</returns>
	static std::string GetXunKong(std::string& ganZhi);

	/// <summary>
	/// 月天干，如己
	/// </summary>

private:
	/// <summary>
	/// 宜忌
	/// </summary>
	static const std::vector<std::string> YI_JI;


	/// <summary>
	/// 每日宜忌数据
	/// </summary>
	static const std::string DAY_YI_JI;

	/// <summary>
	/// 时辰宜忌数据
	/// </summary>
	static const std::string TIME_YI_JI;

	/// <summary>
	/// 神煞
	/// </summary>
	static const std::vector<std::string> SHEN_SHA;

	/// <summary>
	/// 每日神煞数据
	/// </summary>
	static const std::string DAY_SHEN_SHA;

	/// <summary>
	/// 数字转十六进制
	/// </summary>
	/// <param name="n">数字</param>
	/// <returns>十六进制</returns>
	static std::string Hex(int n);





};

